< previous page page_656 next page >

Page 656
Page Locking
The lowest level of locking available in Visual Basic is page-level locking. Page-level locking is handled automatically by the Microsoft Jet engine and cannot be controlled through Visual Basic code or with data-bound control properties. Each time a user attempts to edit or update a record, the Microsoft Jet performs the necessary page locking to ensure data integrity.
What Is Page Locking?
A data page can contain more than one data record. Currently, the Microsoft Jet data page is always 2KB. Locking a data page locks all records that are stored on the same data page. If you have records that are 512 bytes in size, each time Microsoft Jet performs a page lock, four data records are locked. If you have records that are 50 bytes in size, each Microsoft Jet page lock can affect 40 data records.
The exact number of records that are locked on a page cannot be controlled or accurately predicted. If your data table contains several deleted records that have not been compacted out by using the CompactDatabase method, you have "holes" in your data pages. These holes do not contain valid records. Also, data pages contain records that are physically adjacent to each otherregardless of any index, filter, or sort order that has been applied to create the dataset. Even though records in a dataset are listed one after another, they might not be physically stored in the same manner. Therefore, editing one of the dataset records might not lock the next record in the dataset list.
Pessimistic and Optimistic Locking
Even though page-level locking is performed automatically by Microsoft Jet, you can use the LockEdits property of a record set to control how page-locking is handled by your application. Two page-locking modes are available: pessimistic locking (LockEdits=True) and optimistic locking (LockEdits=False). The default locking mode is pessimistic.
In pessimistic locking mode, Microsoft Jet locks the data page whenever the Edit or AddNew method is invoked. The page stays locked until an Update or Cancel method is executed. When a page is locked, no other program or user can read or write any data records on the locked data page until the Update or Cancel method has been invoked. The advantage of using the pessimistic locking mode is that it provides the highest level of data integrity possible at the page level. The disadvantage of using the pessimistic locking mode is that it can lock data pages for a long period of time. This can cause other users of the same database to encounter error messages as they attempt to read or write data in the same table.
In optimistic locking mode, Microsoft Jet only locks the data page whenever the Update method is invoked. Users can invoke the Edit or AddNew method and begin editing data without causing Microsoft Jet to execute a page lock. When the user is done making changes and saves

 
< previous page page_656 next page >

If you like this book, buy it!